package dxn.nl.file.client.model.codec;

import dxn.nl.file.client.model.dto.TransferMessageDto;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 自定义信息编码器
 */
public class MessageEncoder extends MessageToByteEncoder<TransferMessageDto> {
    private static final Logger logger = LoggerFactory.getLogger(MessageEncoder.class);

    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, TransferMessageDto transferMessageDto, ByteBuf out) throws Exception {
        try {
            MessageCodeUtil.encode(out,transferMessageDto);
        } catch (Exception ex) {
            logger.error("", ex);
            throw ex;
        }
    }
}
